'use strict';
	angular.module('inventory.fileStorageMove', ['app.services'])

	.controller('fileStorageMoveCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {

   		var Model = this;
   		
		var billType = 'CKDA';
 		
   		var options = {};
		options.container = Model;
		options.concept = 'FileStorage';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
   		options.creater = '/inventory/fileStorage/tree/create';
   		options.reader = '/inventory/fileStorage/tree/query';
   		options.writer = '/inventory/fileStorage/tree/save';
   		options.deleter = '/inventory/fileStorage/tree/delete';
   		options.idColumnDefine = "fID";
   		options.idColumnName = "fID";
  		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},storageNo:{name:"storageNo",type:"String",label:""},storageName:{name:"storageName",type:"String",label:""},storageType:{name:"storageType",type:"String",label:""},storageTypeLabel:{name:"storageTypeLabel",type:"String",label:""},storageFullID:{name:"storageFullID",type:"String",label:""},storageFullNo:{name:"storageFullNo",type:"String",label:""},storageFullName:{name:"storageFullName",type:"String",label:""},factoryID:{name:"factoryID",type:"String",label:""},factoryNo:{name:"factoryNo",type:"String",label:""},factoryName:{name:"factoryName",type:"String",label:""},factoryType:{name:"factoryType",type:"String",label:""},controlPick:{name:"controlPick",type:"String",label:""},controlCalculate:{name:"controlCalculate",type:"String",label:""},isStore:{name:"isStore",type:"String",label:""},nodeLevel:{name:"nodeLevel",type:"Integer",label:""},nodeKind:{name:"nodeKind",type:"String",label:""},sortNo:{name:"sortNo",type:"String",label:""},fParent:{name:"fParent",type:"String",label:""},contacts:{name:"contacts",type:"String",label:""},mobilePhone:{name:"mobilePhone",type:"String",label:""},fPhone:{name:"fPhone",type:"String",label:""},sMail:{name:"sMail",type:"String",label:""},fProvince:{name:"fProvince",type:"String",label:""},fCity:{name:"fCity",type:"String",label:""},fZone:{name:"fZone",type:"String",label:""},fAddressName:{name:"fAddressName",type:"String",label:""},fAddress:{name:"fAddress",type:"String",label:""},fAddressDetail:{name:"fAddressDetail",type:"String",label:""},images:{name:"images",type:"String",label:""},summary:{name:"summary",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""},del:{name:"del",type:"Integer",label:""},delUserId:{name:"delUserId",type:"String",label:""},delDatetime:{name:"delDatetime",type:"Datetime",label:""}};
   		options.isTree = true;
   		options.parentRelation = 'fParent';
   		options.nodeKindRelation = 'nodeKind';
   		options.nodeLevelRelation = 'nodeLevel';
   		options.nodeSortRelation = "sortNo";
   		options.rootFilter = 'FileStorage.fParent is null';
   		options.pathRelation = 'storageFullID';
   		options.directDeleteMode = false;
   		options.limit = -1;
   		options.orderBy = 'sortNo ASC';

   		Model.dataMaster = new BizData(options);
   		//监视对象中的所有变动
//   	Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
   		//////////////////////////////////////////////

   		Model.dataMaster.filter = "FileStorage.billType='"+billType+"'";
	
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;
     	
       		Model.dataMaster.refreshData();

        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
        	var event = {};
        	if($scope.checkboxValue){
        		event.data = null;
        	}else{
   	    	var data = [];
    	    	var sourceRow = Model.dataMaster.rows[Model.dataMaster.currentIndex];
    	    	var row = {};
    			//循环行中的列，判断变化点是哪一个
    			for(var obj in sourceRow){
    				if(obj!='$$hashKey' && obj!='userdata'){
    					row[obj] = sourceRow[obj].value;
    				}
    			}
    	    	
    	    	data.push(row);
    	    	event.data = data;
        		
        	}
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    



	    return Model;
	    
	}	
	
